<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>KAKA</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4">
 
<link href="/public/css/main.css" rel="stylesheet">
<script type="text/javascript">
    $(document).ready(function () {
        $('._header').width($('.container').width());
    })
</script>
<div class="container" style="background-color: white">
    <div class='_main'>
        <div class="banner">
           <!--  <div class='_logo'>
                <a href='/'><img src="/public/images/kaka.png" class='logo_img'  alt='banner'/></a>
            </div> -->
            <a href='/'><img src="/public/images/banner.png" class='banner_img'  alt='banner'/></a>
        </div>
        <div class='_header'>
            <div style='padding-right: 5rem;padding-top:1px' id="welcome">
                <span class=''><a class='_a' href="/home/passport/login"><img src="/public/images/login.png" width='90px' ></a></span>
                <span class='_span'></span>
                <span class='_span'><a class='_a' href="/home/passport/apply"><img src="/public/images/apply.png" width='90px' ></a></span>
            </div>
            <div style='display:none;color:white' id="already_login">
                <span class='as'><a class='_a color1' href="javascript:void(0);"><b id="login_name"></b><?php if( $msg_num != 0 ){ ?> <a href="/home/message/message"><span class="_message"><?php echo $msg_num; ?></span></a> <?php }?></a> </span>
                <span class='_span as'><b>|</b></span>
                <span class='_span' style="width:7rem"><a class='_a color1' href="/home/passport/repassword"><b>修改密码</b></a></span>
                <span class='_span as'><b>|</b></span>
                <span class='_span'><a class='_a color1' href="/home/passport/logout"><b>退出</b></a></span>
            </div>
        </div>
        <div class="_menu" id='_menu'>
            <div class='_menu_in'>
                <!-- <span class='_menu_b'>
                    <a class='wa' href="/home/company">公司</a>
                </span> -->
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/store')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/store')){?>_a<?php }else{?>wa<?php }?>" href='/home/store'>店铺</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'home/barber')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/barber')){?>_a<?php }else{?>wa<?php }?>" href='/home/barber'>成员</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/action')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/action')){?>_a<?php }else{?>wa<?php }?>" href='/home/action'>活动</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/order')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/order')){?>_a<?php }else{?>wa<?php }?>" href='/home/order'>订单</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/coupon')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/coupon')){?>_a<?php }else{?>wa<?php }?>" href='/home/coupon'>优惠劵</a>
                </span>
                <span class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/goods')){?>_menu_b_2<?php }else{?>_menu_b<?php }?>">
                    <a class="<?php if(strstr(strtolower($_SERVER['REQUEST_URI']),'/home/goods')){?>_a<?php }else{?>wa<?php }?>" href='/home/goods'>商品</a>
                </span>
            </div>
        </div>
        <div class='_line'></div>
 
<div class="_contro">
    <a href="/home/action/" class="_a"><font style='font-size:1.5rem'>返回列表页</font></a>
</div>

<div class='_cut'></div>
<div class='content'>

    <?php if($actions['id']){ ?>
        <form action="/home/action/update" method="post" id='form'>
    <?php }else{ ?>
        <form action="/home/action/submit" method="post" id='form'>
    <?php }?>

            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">营销模式:</label>
                <select name="type" class='_select' id='type'>
                    <?php foreach($action_type as $v){?>
                    <option value="<?php echo $v['id']; ?>" id="model_type_<?php echo $v['id']; ?>" url="<?php echo $v['link']; ?>" <?php if( $v['id'] == 3 ){echo "selected='selected'";}?>><?php echo $v['model_name'];?></option>
                    <?php } ?>
                </select>
                <?php foreach($action_type as $v){ ?>
                <input type='hidden' id="model_<?php echo $v['id'];?>" value="<?php if($actions['model_type']==$v['id']){echo $actions['intro'];}else{echo $v['intro'];}?>"/>
                <?php } ?>
            </div>

            <div>
                <div class="form-group row">
                    <label for="exampleInputName2" class="_label" >活动店铺:</label>
                    <select id="store_id" name="store_id">
                        <option value='0'>全部</option>
                        <?php foreach( $store as $v ){?>
                        <option value="<?php echo $v['id'];?>" <?php if( $actions['store_id']==$v['id'] ){ echo "selected='selected'";}?> > <?php echo $v['name']; ?> </option>
                        <?php }?>
                    </select>
                </div>
            </div>

            <div id='barber_par'>
                <div class="form-group row" id='_barber'>
                    <label for="exampleInputName2" class="_label" >活动成员:</label>
                    <select name="barber" class='_select' id="barber">
                        <option value="0">全部</option>
                        <?php if(isset($barber)){foreach($barber as $v){?>
                        <option value="<?php echo $v['id'];?>" <?php if( $v['id']==$actions['barber_id'] ){ echo "selected='selected'"; }?> >
                        <?php echo $v['name'];?> </option>
                        <?php }}?>
                    </select>
                    <input type='button' value='添加' onclick="javascript:window.open('/home/barber/create');">
                    <span class='_prompt'>如果您想向客人推荐某位发型师或做专人营销活动请填选此处。</span>
                </div>
            </div>

            <div class='form-group row'>
                <label for="exampleInputName2" class="_label" style="margin-left: 0px;" >活动名称:</label>
                <?php if( !empty($actions) ){?>
                <input type="text" class="row _minput" name='action_name' placeholder="" value="<?php echo $actions['action_name'];?>" style="margin-left: 0px;" />
                <?php }else{?>
                <input type="text" class="row _minput" name='action_name' placeholder="" value="" style="margin-left: 0px;" />
                <span class="_prompt">活动名称，主题 例如：“周年庆拼团活动”</span>
                <?php } ?>
            </div>

            <div id='type_model' >
                <div class='form-group row' id='item_name' >
                    <label for="exampleInputName2" class="_label">活动项目:</label>
                    <?php $actions['content'] = json_decode( $actions['content'],true ); $arr=$actions['content']['content']; if( $actions['id']<1 || $actions['content']['ids']!=false ){ ?>
                        <select id="item_select" class="_select valid">
                            <option value='0'>请选择</option>
                        </select>&nbsp;&nbsp;&nbsp;
                        <span> <a href="javascript:;"  id='create_good' >点击创建商品</a></span>
                    <?php } ?>

                    <!-- 商品 详情 start -->
                    <div class="row" id='item_list'style="margin-left: 13rem">
                    <div class='form-group row' id='item_list_' >

                            <?php if( $actions['id'] ){ $content_key = array_keys( $actions['content']['ids']); ?>
                            <?php if( $_item!=false || $actions['id']<1 || $_item[0]['id'] == $content_keys[0] ){ $v = $_item[0]; ?>
                                    <div class="col-sm-4 col-md-3 full">
                                        <input type='hidden' id='items_<?php echo $v['id'];?>' value='<?php echo $v['id'];?>' name='items[]'>
                                        <div class="thumbnail" style="margin-bottom:10px;">
                                            <div style="height:21rem; overflow: hidden;text-align:center">
                                                <img class="_img" src="http://<?php echo IMAGE_DOMAIN.$v['images'][0]['image'];?>" style="width:100%;height:100%">
                                            </div>
                                        </div>
                                        <div class="caption" style="overflow: hidden">
                                            <div style="font-size:1.8rem">
                                                <div>
                                                    <img class="_img" src="/public/images/<?php echo $v['img'];?>" style="width:28%;">
                                                    <span style="margin-left: 6px;font-size:2rem;"><?php echo $v['name'];?></span>
                                                </div>
                                                <div>价格：<?php echo $v['price']/100;?>元 </div>
                                                <div>众筹价：<input type="text" value="<?php echo $actions['content']['ids'][$v['id']]/100; ?>" style="width:30%" name="real_price[]">元</div>
                                            </div>
                                        </div>
                                    </div>
                            <?php } ?>
                            <?php } ?>

                    </div>
                    </div>
                    <!-- 商品 详情 end -->

                </div>
            </div>

            <div id='send_model' >
                <div class='form-group row' id='send_name' >
                    <label for="exampleInputName2" class="_label">公益名称:</label>
                    <input type="text" class="row _minput" name='crowd_name' placeholder="公益名称" value=" <?php echo $actions['content']['crowd_name']; ?>" style="margin-left: 0px;" />
                    <div class='_line'></div>
                    
                    <span id='asd' style='float:left' >
                    <label for="exampleInputName2" class="_label" ></label>
                    <img src="<?php if($actions['logo']){ echo "http://".IMAGE_DOMAIN.$actions['logo']; }else{ echo "http://".IMAGE_DOMAIN.'/upload/crowd.png'; } ?>" style="width:40rem;height:20rem;border:1px;border-color: black" id="s0_img"  alt='公益图'/>
                    <input type='hidden' name='logo' value="<?php if($actions['logo']){ echo $actions['logo']; }else{ echo '/upload/crowd.png'; } ?>" id='s0'>
                    <div >
                        <label for="exampleInputName2" class="_label"></label>
                        <iframe id='imgs' src="http://<?php  echo IMAGE_DOMAIN;?>/index.php?id=s0&type=2" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem" ></iframe>
                        <span class="_prompt">宣传用图片建议长宽比例2:1；2M以内，支持“jpg,jpeg,png”</span>
                    </div> 
                    </span>



                </div>
            </div>



            <div id='model'>
                <div class='form-group row'>
                    <label for="exampleInputName2" class="_label">活动开始日期:</label>
                    <?php if($actions['start_time']>0){?>
                    <input type="text" class="row _minput" name='start_time' placeholder="" value="<?php echo date('Y-m-d',$actions['start_time']);?>" onfocus="WdatePicker();" onblur="" style="margin-left: 0px;" />
                    <?php }else{?>
                    <input type="text" class="row _minput" name='start_time' placeholder="" value="" onfocus="WdatePicker();" onblur="" style="margin-left: 0px;" />
                    <?php }?>
                </div>
                <div class='form-group row'>
                    <label for="exampleInputName2" class="_label">活动结束日期:</label>
                    <?php if($actions['end_time']>0){?>
                    <input type="text" class="row _minput" name='end_time' placeholder="" value="<?php echo date('Y-m-d',$actions['end_time']);?>" onfocus="WdatePicker();" onblur="" style="margin-left: 0px;" />
                    <?php }else{?>
                    <input type="text" class="row _minput" name='end_time' placeholder="" value="" onfocus="WdatePicker();" onblur="" style="margin-left: 0px;" />
                    <?php }?>
                </div>
                <div class='form-group row'>
                    <label for="exampleInputName2" class="_label">使用截止日期:</label>
                    <?php if($actions['end_time']>0){?>
                    <input type="text" class="row _minput" name='use_end_time' placeholder="" value="<?php echo date('Y-m-d',$actions['use_end_time']);?>" onfocus="WdatePicker();" onblur="" style="margin-left: 0px;" />
                    <?php }else{?>
                    <input type="text" class="row _minput" name='use_end_time' placeholder="" value="" onfocus="WdatePicker();" onblur="" style="margin-left: 0px;" />
                    <?php }?>
                </div>
            </div>

            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">是否允许重复购买:</label>
                <input type="radio" name="only" value="2" <?php if($actions['only']==2){ echo 'checked=checked'; } ?> >允许
                <input type="radio" name="only" value="1" <?php if($actions['only']==1){ echo 'checked=checked'; } ?> >不允许
            </div>

            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">活动介绍:</label>
                <?php if(!empty($actions)){?>
                <textarea name='intro' id="_intro" class="_textarea"><?php echo $actions['intro']; ?></textarea>
                <?php }else{?>
                <textarea name='intro' id="_intro" class="_textarea"></textarea>
                <?php }?>
            </div>
            <div class="form-group _submit_div row">
                <input name='id' type='hidden' value="<?php echo $actions['id'];?>"/>
                <input name='create' id='create' class='_button' type="button" value="预览" onclick="_submit(2);"/>
                <input name='caogao' id='caogao' class='_button' type="submit" value="保存草稿" onsubmit="return _submit(1);"/>
            </div>

        </form>
</div>
<script type='text/javascript' src='/public/js/date/WdatePicker.js'></script>
<script type='text/javascript'>

    $(document).ready(function () {

        // 获取店铺商品信息
        var store_id = $("#store_id").val();
        if( store_id>0 ){
            getItem( store_id );
        }

        // 修改活动介绍
        var id = $('#type').val();
        var str = $('#model_' + id).val();
        $("#_intro").html(str);

        // 选择店铺
        $("#store_id").change(function () {
            store_id = $("#store_id").val();
            getBarber( store_id );
            getItem( store_id );
        });

        // 商品改变
        $("#item_select").change(function(){
            var id = $('#item_select').val();
            if ( id < 1 ){
                // $("#item_list").append('');
                return;
            }
            $("#item_list").empty();
            var html = getShopContent( id,'shop' );
            $("#item_list").append(html);
            var _html = "<input type='hidden' id='items_"+id+"' value='"+id+"' name='items[]'>";
            $("#item_list").append(_html);
        });

        //创建商品
        $('#create_good').click(function(){
            var htmls = "<input type='hidden' name='st' value='1' >";
            $(this).parent().append(htmls);
            window.open("/home/goods/create");  
        });

        $('#item_select').click(function(){
            if($('#create_good').next().val()){
                getItem(store_id);
                $('#create_good').next().remove();
            }
            
        });

        // 表单验证
        $("#form").validate({
            rules: {
                store_id: {
                    required: true,
                    min: 1,
                },
                action_name: {
                    required: true,
                },
                type: {
                    required: true,
                    number: true
                },
                start_time: {
                    required: true,
                },
                end_time: {
                    required: true,
                },
                use_end_time:{
                    required: true,
                },
                intro: {
                    required: true,
                },
                only: {
                    required: true,
                }
            },
            messages: {
                store_id: {
                    required: "请选择活动店铺",
                    min: "请选择活动店铺",
                },
                action_name: {
                    required: '请输入活动名称',
                },
                type: {
                    required: '请选择活动类型',
                },
                start_time: {
                    required: '请选择活动开始日期',
                },
                end_time: {
                    required: '请选择活动结束日期',
                },
                use_end_time:{
                    required: '请选择使用截止日期',
                },
                intro: {
                    required: '请填写活动介绍',
                },
                only: {
                    required: '请选择是否允许重复购买',
                }
            },
            errorPlacement: function (error, element) { //指定错误信息位置
                if (element.is(':radio') ) { //如果是radio或checkbox
                    var eid = element.attr('name'); //获取元素的name属性
                    error.appendTo(element.parent()); //将错误信息添加当前元素的父结点后面
                } else {
                    error.insertAfter(element);
                }
            }
        });
        /////////////////////////////////////////////////////////////

    });








    // 选择活动模式
    $("#type").change(function () {
        var id = $('#type').val();
        var str = $('#model_' + id).val();
        $("#_intro").html(str);
        if (id != 3) {
            var link = $('#model_type_'+id).attr("url");
            window.location.href = '/home/action/create?model_id='+id+'&model='+link;
            return;
        }
        window.location.reload();
    });

    // 获取发型师
    function getBarber( store_id ){
        $.ajax({
            url: "/home/action/getbarber?store_id=" + store_id,
            async: true,
            success: function (data) {
                if (data == 'false') {
                    return;
                }
                data = eval('(' + data + ')');
                var str = "<option value='0'>全部</option>";
                $.each(data, function (i, v) {
                    str += "<option value='" + v.id + "'>" + v.name + "</option>"
                });
                $('#barber').html(str);
            }
        });
    }

    // 获取商品信息
    function getItem( store_id ){
        var img_domain = "http://<?php echo IMAGE_DOMAIN;?>";
        $.ajax({
            url: "/home/action/items?store_id=" + store_id,
            async: true,
            success: function (data) {
                if (data == 'false') {
                    return;
                }
                data = eval('(' + data + ')');
                var str = "<option value='0'>请选择</option>";
                var str2 = '';
                $.each(data, function (i, v) {
                    var image = '';
                    str += "<option value='" + v.id + "'>" + v.name + "</option>";
                    $.each(v.images,function (ii,vv){
                        if(ii==0){
                            image = img_domain+vv.image;
                            return false;
                        }
                    });
                    v.price = v.price/100;
                    str2 += "<input type='hidden' value='"+v.id+"' id='item_"+v.id+"' _name='"+v.name+"' img='"+image+"' _img='/public/images/"+v.img+"' price='"+v.price+"'>";
                });
                $('#item_select').html( str );
                //$('#send_select').html( str );
                $('body').append(str2);
            }
        });
    }

    // 展示商品详细信息
    function getShopContent( id,type ){
        var image = $("#item_"+id).attr('img');
        var name = $("#item_"+id).attr('_name');
        var _img = $("#item_"+id).attr("_img");
        var price = $("#item_"+id).attr("price");
        var html = '<div class="col-sm-4 col-md-3 full"><div class="thumbnail" style="margin-bottom:10px"><div style="height: 21rem;overflow: hidden;text-align:center"><img class="_img" src="';
        html += image;
        html += '"style="width:100%;height:100%"></div></div>';

        html += '<div class="caption" style="overflow: hidden"><div style="font-size:1.8rem"><div><img class="_img" src="';
        html += _img;
        html += '" style="width:28%;"><span style="margin-left: 6px;font-size:2rem;">';
        html += name;
        html += '<div>原价：'+price+'元</div>';
        if ( type == 'shop' ){
            html += '<div>众筹价：<input type="text" value="" style="width:30%" name="real_price[]">元</div>';
        }
        html += '</span></div></div></div></div>';
        return html;
    }

    // 提交活动
    function _submit(type) {
        if (type == 1) {
            $('#create').remove();
        } else {
            $('#caogao').remove();
        }
        var content = $("#_intro").val();
        content = content.replace(/<br\/>/,"\n");
        content = content.replace(/<span style=\'color:red\'>/,"");
        content = content.replace(/<\/span>/,"");
        content = content.replace(/\n/g, "<br/>");
        content = content.replace(/[\d]{1,}/g, "<span style='color:red'>$&</span>");
        $("#_intro").val(content);
        $('#form').submit();
    }


</script>
<style>.error{padding-left:2rem}</style>
</div>
<div class="_line"></div>
<div class="_footer">
    ©2015-<?php echo date('Y');?> All Rights Reserved ( 京ICP备15010043号 )
</div>
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
    background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
    </body>
</html>